package com.yunhe.service;

import java.util.List;

import org.apache.catalina.mapper.Mapper;
import org.apache.ibatis.session.SqlSession;

import com.yun.dao.AddMainDao;

import com.yun.dao.AdminDelete;
import com.yun.dao.AdminFenYe;
import com.yun.dao.AdminSelect;
import com.yun.dao.AdminStop;
import com.yunhe.bean.Admin;
import com.yunhe.util.MySession;

public class AdminService {
	//检查用户名
	public boolean checkAdmin(Admin admin){
		SqlSession se=new MySession().getSession();
		AddMainDao mapper = se.getMapper(AddMainDao.class);
		List<Admin> list=mapper.checkAdmin(admin);
		boolean b =true;
		if(list.size()>0){
			b=false;
		}else{
			b=true;
		}
		return b;
		
	}
	//增加用户
	public int submitAdmin(Admin admin){
		SqlSession se=new MySession().getSession();
		AddMainDao mapper = se.getMapper(AddMainDao.class);
		int a=mapper.addAdmin(admin);
		se.commit();
		
		return a;
	}
	//查询所有管理员
	public List<Admin> getCount(){
		SqlSession se =new MySession().getSession();
		AdminFenYe mapper =se.getMapper(AdminFenYe.class);
		List<Admin> count =mapper.getCount();
		return count;
		
	}
	//查询管理员（分页）
	public List<Admin> getFenye(int row){
		SqlSession se =new MySession().getSession();
		AdminFenYe mapper =se.getMapper(AdminFenYe.class);
		List<Admin> admin =mapper.getFenye(row);
		return admin;
		
	}
	//停用管理员
	public int  stopAdmin(Admin admin){
		SqlSession se =new MySession().getSession();
		AdminStop mapper =se.getMapper(AdminStop.class);
		int a  =mapper.StopAdmin(admin);
		se.commit();
		return a;
		
		
	}
	//启用管理员
	public int startAdmin(Admin admin){
		SqlSession se =new MySession().getSession();
		AdminStop mapper =se.getMapper(AdminStop.class);
		int a  =mapper.StartAdmin(admin);
		se.commit();
		return a;
		
	}
	//删除管理员
	public int deleteAdmin(Admin admin){
		SqlSession se =new MySession().getSession();
		AdminDelete mapper =se.getMapper(AdminDelete.class);
		int a =mapper.getDelete(admin);
		se.commit();
		return a;
	}
	//搜索管理员
	public List<Admin> selectAdmin(Admin admin){
		SqlSession se =new MySession().getSession();
		AdminSelect mapper =se.getMapper(AdminSelect.class);
		List<Admin> list =mapper.getList(admin);
		return list;
	}
	
	//批量删除


}
